package com.csun.cmny.provider.controller.message.scheadule;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.provider.controller.message.AbstractCurTaskQueryProcessor;
import com.csun.cmny.provider.dto.OrderQueryDto;
import com.csun.cmny.provider.model.vo.RpcRoleVo;
import com.csun.cmny.provider.model.vo.message.ScheduleVo;
import com.csun.cmny.provider.service.OmcScheduleService;
import com.csun.cmny.provider.service.UacRpcService;
import com.csun.cmny.provider.utils.MenuTimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
public class ScheaduleTaskQuery extends AbstractCurTaskQueryProcessor<ScheduleVo> {

    @Resource
    private UacRpcService uacRpcService;
    @Resource
    private OmcScheduleService omcScheduleService;


    @Override
    protected List<ScheduleVo> queryCurTaskList(LoginAuthDto loginAuthDto) {

        List<RpcRoleVo> rpcRoleVos = uacRpcService.queryRoleListByUserId(loginAuthDto.getUserId());
        List<String> roleCodes = rpcRoleVos.stream().map(r->r.getRoleCode()).collect(Collectors.toList());
        if(roleCodes.contains("serviceMinister")){
            //获取当日日期
            String thisDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            //获取本周周数
            String thisWeek = MenuTimeUtil.getDays(thisDate).get(1) + MenuTimeUtil.getDays(thisDate).get(0);
            return omcScheduleService.queryScheduleCurTaskList(thisWeek,loginAuthDto);
        }
        return null;
    }

    @Override
    protected List<ScheduleVo> queryCurOrderList(OrderQueryDto orderQueryDto, LoginAuthDto loginAuthDto) {
        return null;
    }
}
